<?php

/**
 * comment actions.
 *
 * @package    hacride
 * @subpackage comment
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class commentActions extends autocommentActions
{
  public function executeEdit()
  {
    $this->comment = $this->getCommentOrCreate();


    if ($this->getRequest()->getMethod() != sfRequest::POST)
    {
      if ($this->getRequestParameter('post_id'))
      {
        $this->comment->setPostId($this->getRequestParameter('post_id'));
      }
      $this->labels = $this->getLabels();
    }
    else
    {
      $this->updateCommentFromRequest();

      $this->saveComment($this->comment);

      $this->setFlash('notice', 'Your modifications have been saved');

      if ($this->getRequestParameter('save_and_add'))
      {
        return $this->redirect('comment/create');
      }
      else if ($this->getRequestParameter('save_and_list'))
      {
        return $this->redirect('comment/list');
      }
      else
      {
        return $this->redirect('comment/edit?id='.$this->comment->getId());
      }
    }

  }
  
  public function executeIsHam()
  {
    $comment = CommentPeer::retrieveByPK($this->getRequestParameter('id'));
    
    $akismet = new Zend_Service_Akismet(sfConfig::get('app_akismet_key'), sfConfig::get('app_url'));
  	  
  	$akismet_data = array(
  	  'user_ip'              => http::realIP(),
      'user_agent'           => $_SERVER['HTTP_USER_AGENT'],
      'comment_type'         => 'comment',
      'comment_author'       => $comment->getName(),
      'comment_author_email' => $comment->getMail(),
      'comment_content'      => $comment->getBody()
  	);
  	
  	$akismet->submitHam($akismet_data);
  	
  	$comment->setIsSpam(false);
  	$comment->save();
  	
  	$this->redirect('comment/index');
  }
  
  public function executeIsSpam()
  {
    $comment = CommentPeer::retrieveByPK($this->getRequestParameter('id'));
    
    $akismet = new Zend_Service_Akismet(sfConfig::get('app_akismet_key'), sfConfig::get('app_url'));
  	  
  	$akismet_data = array(
  	  'user_ip'              => http::realIP(),
      'user_agent'           => $_SERVER['HTTP_USER_AGENT'],
      'comment_type'         => 'comment',
      'comment_author'       => $comment->getName(),
      'comment_author_email' => $comment->getMail(),
      'comment_content'      => $comment->getBody()
  	);
  	
  	$akismet->submitSpam($akismet_data);
  	
  	$comment->setIsSpam(true);
  	$comment->save();
  	
  	$this->redirect('comment/index');
  }
  
}
